/**
 * 
 */
package com.tech.freak.pyp;

import com.tech.freak.pyp.data.PicoyPlaca.PYP;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * @author julian
 *
 */
public class PyPDataAdapter extends CursorAdapter {

	public PyPDataAdapter(Context context, Cursor cursor) {
		super(context, cursor);
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see android.support.v4.widget.CursorAdapter#bindView(android.view.View, android.content.Context, android.database.Cursor)
	 */
	@Override
	public void bindView(View convertView, Context context, Cursor cursor) {
		ViewHolder holder = (ViewHolder) convertView.getTag();
		
		holder.city.setText(cursor.getString(cursor.getColumnIndex(PYP.CITY)));
		holder.monday.setText(cursor.getString(cursor.getColumnIndex(PYP.MONDAY)));
		holder.tuesday.setText(cursor.getString(cursor.getColumnIndex(PYP.TUESDAY)));
		holder.wednesday.setText(cursor.getString(cursor.getColumnIndex(PYP.WEDNSEDAY)));
		holder.thursday.setText(cursor.getString(cursor.getColumnIndex(PYP.THURSDAY)));
		holder.friday.setText(cursor.getString(cursor.getColumnIndex(PYP.FRIDAY)));
		holder.saturday.setText(cursor.getString(cursor.getColumnIndex(PYP.SATURDAY)));
		holder.sunday.setText(cursor.getString(cursor.getColumnIndex(PYP.SUNDAY)));
	}

	/* (non-Javadoc)
	 * @see android.support.v4.widget.CursorAdapter#newView(android.content.Context, android.database.Cursor, android.view.ViewGroup)
	 */
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.pyp_data_item, parent, false);
		
		ViewHolder holder = new ViewHolder();
		
		holder.city = (TextView) v.findViewById(R.id.city);
		holder.monday = (TextView) v.findViewById(R.id.monday_content);
		holder.tuesday = (TextView) v.findViewById(R.id.tuesday_content);
		holder.wednesday = (TextView) v.findViewById(R.id.wednesday_content);
		holder.thursday = (TextView) v.findViewById(R.id.thursday_content);
		holder.friday = (TextView) v.findViewById(R.id.friday_content);
		holder.saturday = (TextView) v.findViewById(R.id.saturday_content);
		holder.sunday = (TextView) v.findViewById(R.id.sunday_content);
		
		v.setTag(holder);
		
		return v;
	}

	private class ViewHolder {
		TextView city;
		TextView monday;
		TextView tuesday;
		TextView wednesday;
		TextView thursday;
		TextView friday;
		TextView saturday;
		TextView sunday;
	}
}
